load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_license//rules:license.bzl", "license")

package(
    default_applicable_licenses = [":license"],
)

license(
    name = "license",
    package_name = "ccd",
    license_kinds = ["@rules_license//licenses/spdx:BSD-3-Clause"],
    license_text = ":BSD-LICENSE",
)

ccd_sources = glob(
    include = [
        "src/*.c",
    ],
)

ccd_headers = glob(
    include = [
        "src/*.h",
    ],
)

ccd_public_headers = glob(
    include = [
        "src/ccd/*.h",
    ],
)

expand_template(
    name = "config",
    out = "src/ccd/config.h",
    substitutions = {"#cmakedefine": "// #undef"},
    template = "src/ccd/config.h.cmake.in",
)

cc_library(
    name = "ccd_single",
    srcs = ccd_sources + ccd_headers,
    hdrs = ccd_public_headers + ["src/ccd/config.h"],
    defines = ["CCD_SINGLE"],
    includes = ["src"],
    visibility = ["//visibility:public"],
)

cc_library(
    name = "ccd",
    srcs = ccd_sources + ccd_headers,
    hdrs = ccd_public_headers + ["src/ccd/config.h"],
    defines = ["CCD_DOUBLE"],
    includes = ["src"],
    visibility = ["//visibility:public"],
)
